package com.example.stars_project_android.index;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;

import com.example.stars_project_android.R;
import com.example.stars_project_android.adapter.GuestBookAdapter;
import com.example.stars_project_android.adapter.MyGuestBookAdapter;
import com.example.stars_project_android.entity.GuestBookEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的留言页面
 */
public class Myguestbook extends AppCompatActivity implements View.OnClickListener{


    private ListView listview;
    private List<GuestBookEntity> myList = new ArrayList<>();
    private MyGuestBookAdapter myGuestBookAdapter = null;

    private ImageButton myGuestBookToUser;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myguestbook);

        //绑定控件对象
        setView();
        //设置数据源
        myList = setData();
        //绑定适配器
        myGuestBookAdapter = new MyGuestBookAdapter(
                this,
                R.layout.guestbook_item,
                myList
        );
        listview.setAdapter(myGuestBookAdapter);

    }

    /**
     * 设置数据源
     * @return
     */
    private List<GuestBookEntity> setData() {
        List<GuestBookEntity> myList = new ArrayList<>();
        GuestBookEntity guestBook = new GuestBookEntity();
        guestBook.setUserImg(R.mipmap.user_img1);
        guestBook.setUserId("HD 489-1622-1");
        guestBook.setUserMessage("愿你在今日能与开心和快乐撞个满怀!");
        guestBook.setMessageTime("2022-12-28 15:17:23");
        guestBook.setLikeNum("16");
        myList.add(guestBook);
        GuestBookEntity guestBook1 = new GuestBookEntity();
        guestBook1.setUserImg(R.mipmap.user_img1);
        guestBook1.setUserId("HD 489-1622-1");
        guestBook1.setUserMessage("卡塔尔世界杯！！！！");
        guestBook1.setMessageTime("2022-12-18 21:10:36");
        guestBook1.setLikeNum("359");
        myList.add(guestBook1);
        GuestBookEntity guestBook2 = new GuestBookEntity();
        guestBook2.setUserImg(R.mipmap.user_img1);
        guestBook2.setUserId("HD 489-1622-1");
        guestBook2.setUserMessage("又是熬夜的一天。。。");
        guestBook2.setMessageTime("2022-12-16 23:16:31");
        guestBook2.setLikeNum("27");
        myList.add(guestBook2);
        GuestBookEntity guestBook3 = new GuestBookEntity();
        guestBook3.setUserImg(R.mipmap.user_img1);
        guestBook3.setUserId("HD 489-1622-1");
        guestBook3.setUserMessage("想一个人撑着伞去江南走走！");
        guestBook3.setMessageTime("2022-11-24 07:45:02");
        guestBook3.setLikeNum("30");
        myList.add(guestBook3);
        GuestBookEntity guestBook4 = new GuestBookEntity();
        guestBook4.setUserImg(R.mipmap.user_img1);
        guestBook4.setUserId("HD 489-1622-1");
        guestBook4.setUserMessage("今天是代码的世界！");
        guestBook4.setMessageTime("2022-11-09 16:20:06");
        guestBook4.setLikeNum("87");
        myList.add(guestBook4);
        return myList;
    }

    private void setView() {
        listview = findViewById(R.id.lv_my_guestbook);
        myGuestBookToUser = findViewById(R.id.ib_my_guestbook_return);
        myGuestBookToUser.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ib_my_guestbook_return:
                Intent intent = new Intent(this, Index.class);
                intent.putExtra("index",4);
                startActivity(intent);
                break;
        }

    }
}